using System;
using System.Collections;
using System.Collections.Generic;
using Assets.Scripts;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class ShopItem : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
    public Image icon, Minicon, LeftIcon,RightIcon;
     public Text  Name;
    public Text Des;
    public ShopData datas;
    public Button ButLeft, ButRight;
    // public Button buy;

    public static ShopItem ins;
    void Awake()
    {
        ins = this;
    }
    public void OnPointerEnter(PointerEventData eventData)
    {
        //UIManager.ins.OpenUI("UIPanel/RightPropTipsPanel");
      SetData(datas);
    }

    private void SetData(ShopData datas)
    {
        if (datas != null)
        {
            Name.text = "属性:" + datas.name + "\n";
            Minicon.sprite = Resources.Load<Sprite>(datas.icon);
            LeftIcon.sprite = Resources.Load<Sprite>(datas.LeftIcon);
            RightIcon.sprite = Resources.Load<Sprite>(datas.RightIcon);
            Des.text = datas.Des;
        }

        ButLeft.onClick.AddListener(() =>
        {
            if (datas != null)
            {
                Minicon.sprite = Resources.Load<Sprite>(datas.LeftIcon);
                LeftIcon.sprite = Resources.Load<Sprite>(datas.icon);
                Des.text = datas.Des;
                   Name.text = "属性:" + datas.name + "\n";
            }
        });
        ButRight.onClick.AddListener(() =>
        {
            if (datas != null)
            {
                Minicon.sprite = Resources.Load<Sprite>(datas.RightIcon);
                RightIcon.sprite = Resources.Load<Sprite>(datas.icon);
            }
        });
    }

    public void OnPointerExit(PointerEventData eventData)
    {
        if (datas != null)
        {
            //ShopTips.ins.Tips.gameObject.SetActive(false);
           // UIManager.ins.CloseUI("UIPanel/RightPropTipsPanel");
        }
    }

    public void RefreshData(ShopData data)
    {
        
        datas = data;
        if (data != null )
        {
            // Name.text = data.name+"\n";
            icon.sprite = Resources.Load<Sprite>(data.icon);
            // num.text = "数量:" + data.num.ToString();
            // if (data.num <= 0)
            // {
            //     num.text = "已售馨";
            //     buy.interactable = false;
            // }
            icon.gameObject.SetActive(true);
            gameObject.SetActive(true);
        }
        else
        {
            icon.gameObject.SetActive(false);
            gameObject.SetActive(false);
        }
       
    }

    void Start()
    {
       
    }

   

   
}
